<template>
  <div>
    AAAA
    <p>{{ num }}</p>
  </div>
</template>

<script>
export default {
  name: "AComp",
  data() {
    return {
      num: 0,
    };
  },
  mounted() {
    // 绑定事件：接受数据（被修改数据）方
    this.$globalEventBus.$on("add", (val) => {
      this.num += val;
    });
  },
  beforeDestroy() {
    this.$globalEventBus.$off("add");
  },
};
</script>

<style>
</style>